package com.lfg.leetcode.leetcode0;

public class No83deleteDuplicates {

    public static void main(String[] args) {
        ListNode ret = deleteDuplicates(ListNode.deserialize("[1,5,5,5]"));
        while (ret != null) {
            System.out.println("[" + ret.val + "]");
            ret = ret.next;
        }
    }

    public static ListNode deleteDuplicates(ListNode head) {
        if (null == head) {
            return null;
        }
        ListNode lastNode = head;
        ListNode currentNode = head;
        while (currentNode.next != null) {
            if (currentNode.val == currentNode.next.val) {
                currentNode = currentNode.next;
                continue;
            }

            lastNode.next = currentNode.next;
            lastNode = lastNode.next;

            currentNode = currentNode.next;
        }
        lastNode.next = null;
        return head;
    }

}

